<template>
  <div class="my-goods-list">
    <MyTable :arr="list">
      <template #head>
        <tr>
          <th>#</th>
          <th>商品名称</th>
          <th>价格</th>
          <th>标签</th>
          <th>操作</th>
        </tr>
      </template>
      <template #body="scoped">
        <td>{{ scoped.obj.id }}</td>
        <td>{{ scoped.obj.goods_name }}</td>
        <td>{{ scoped.obj.goods_price }}</td>
        <td>
          <div>
            <!-- 输入框 -->
            <input
              style="width: 150px"
              class="tag-input form-control"
              type="text"
              v-model="scoped.obj.inputValue"
              v-if="scoped.obj.inputVisble"
              v-focus
              @blur="scoped.obj.inputVisble = false"
              @keyup.esc="scoped.obj.inputValue = ''"
            />
            <button
              v-else
              @click="scoped.obj.inputVisble = true"
              class="btn btn-primary btn-sm add-tag"
            >
              +Tag
            </button>
          </div>

          <span
            class="badge bg-warning text-dark"
            v-for="(item, index) in scoped.obj.tags"
            :key="index"
          >
            {{ item }}</span
          >
        </td>
        <td>
          <button class="btn btn-danger btn-sm" @click="del(scoped.obj.id)">
            删除
          </button>
        </td>
      </template>
    </MyTable>
  </div>
</template>

<script>
import axios from "axios";
import MyTable from "../components/MyTable.vue";
// 接口：GTE  https://www.escook.cn/api/goods

export default {
  data() {
    return {
      list: [],
    };
  },
  components: {
    MyTable,
  },
  async created() {
    const { data } = await axios.get("https://www.escook.cn/api/goods");
    this.list = data.data;
    console.log(data);
  },
  methods: {
    del(id) {
      this.list = this.list.filter((item) => item.id !== id);
    },
  },
};
</script>

<style>
</style>
